﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ChronoScript_Compiler.Language.Parser
{
    public partial class Parser
    {
        public Language.LanguageDefinition.Declaration ParseDeclaration()
        {
            if (PeekToken() is Tokens.Statement && PeekToken(1) is Tokens.Statement)
            {
                string Type = ReadToken().ToString();
                string Name = ReadToken().ToString();
                LanguageDefinition.Declaration decl;
                if (PeekToken() is Tokens.Assign)
                {
                    ReadToken();
                    decl = new LanguageDefinition.Declaration(Name, Type, ParseExpression());
                }
                else
                {
                    decl = new LanguageDefinition.Declaration(Name, Type);
                }
                return decl;
            }
            else
            {
                Console.WriteLine("Declaration Excepted");
                throw new Exception("Declaration Excepted");
            }
        }
    }
}
